/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.sad.controller;

import com.google.gson.Gson;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 
import pe.edu.upc.sad.model.Reserva;
import pe.edu.upc.sad.model.Usuario;

/**
 *
 * @author u913952
 */
public class HolaServlet extends HttpServlet {
   
   /* @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res)
    {
        System.out.println("LoginServlet");

    }*/

    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException {



       //String myString = new JSONObject().put("JSON", "Hello, World!").toString();

        String var=request.getParameter("prueba").toString();
        Usuario obj = new Usuario();
        obj.setDni("44354229");
        obj.setNombres(var);

         Usuario obj1 = new Usuario();
        obj1.setDni("44354229");
        obj1.setNombres("cristianvvv");

        List<Usuario> oUsu=new ArrayList<Usuario>();
        oUsu.add(obj1);
        oUsu.add(obj);
        Gson gson = new Gson();
        String json = "{'Usuario':";
         json += gson.toJson(oUsu) + "}";// gson.toJson(obj);

        String message;
        try {
            message = "100 ok";
        } catch (Throwable t) {
            message = "200 " + t.toString();
        }
        //response.setContentType("text/plain");
        response.setContentType("text/x-json;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        //response.setContentLength(message.length());
        PrintWriter out = response.getWriter();
        out.println(json);

        out.close();
        out.flush();
    }

    @Override
    public void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException {



       String var=request.getParameter("prueba").toString();
        Usuario obj = new Usuario();
        obj.setDni("44354229");
        obj.setNombres(var);

         Usuario obj1 = new Usuario();
        obj1.setDni("44354229");
        obj1.setNombres("cristianvvv");

        List<Usuario> oUsu=new ArrayList<Usuario>();
        oUsu.add(obj1);
        oUsu.add(obj);
        Gson gson = new Gson();
        String json = "{'Usuario':";
         json += gson.toJson(oUsu) + "}";// gson.toJson(obj);

        String message;
        try {
            message = "100 ok";
        } catch (Throwable t) {
            message = "200 " + t.toString();
        }
        //response.setContentType("text/plain");
        response.setContentType("text/x-json;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        //response.setContentLength(message.length());
        PrintWriter out = response.getWriter();
        out.println(json);

        out.close();
        out.flush();
    }

}
